import Vue from 'vue'
import VueRouter from 'vue-router'
import HomeView from '../views/HomeView.vue'

Vue.use(VueRouter)

const routes = [
    {
        path: '/',
        component: HomeView,
        redirect: '/index',
        children: [
             {
                path: '/ei',
                component: () => import('../views/back/1/EmpInfo')
            }, {
                path: '/mm',
                component: () => import('../views/back/1/MenuManagement')
            },{
                path: '/rm',
                component: () => import('../views/back/1/RoleManagement')
            },{
                path: '/pa',
                component: () => import('../views/back/1/PerformanceAssessment')
            },
            {
                path: '/pa',
                component: () => import('../views/back/1/RoleManagement')
            },{
                path: '/ar',
                component: () => import('../views/back/2/AddRoom')
            }, {
                path: '/rs2',
                component: () => import('../views/back/2/RoomStyle')
            },
            {
                path: '/go',
                component: () => import('../views/back/3/GenerateOrder')
            },
            {
                path: '/ol',
                component: () => import('../views/back/3/OrderList')
            },
            {
                path: '/ci',
                component: () => import('../views/back/4/CustomerInput')
            }, {
                path: '/or',
                component: () => import('../views/back/4/OccupancyRate')
            },{
                path: '/sl',
                component: () => import('../views/back/4/ServiceList')
            },{
                path: '/wst',
                component: () => import('../views/back/4/WageStatisticsTwo')
            },

        ]
    },
    {
        path: '/login',
        component: () => import('../views/LoginView.vue')
    },
    {
        path: '/home',
        component: () => import('../views/HomeView.vue')
    },{
        path: '/index',
        component: () => import('../views/back/1/IndexPage.vue')
    }
]


const router = new VueRouter({
    mode: 'history',
    base: process.env.BASE_URL,
    routes
})
router.beforeEach((to,from,next) => {
    if(to.path === "/login"){
        return next()
    }
    let token = localStorage.getItem("jwt")
    if(token){
      return next()
    }
    next("/login")
})
export default router
